/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred;

/**
 * Modelliert die Fragen mit allen Feldenr aus der Datenbank
 * 
 * @author mordredd666
 * 
 */
public class Frage
{

	private int _nummer;
	private String _fragetext;
	private byte[] _bild;
	private String[] _antworten;
	private Object[] _antwortbilder;
	private int _richtigeantwort;
	private String _fach;
	private String _thema;
	private int _jahr;
	private String _notiz;
	private int _fragenummer;
	private int _fragetag;

	private int _selectedAntwort;

	public Frage(int nummer, String fragetext, byte[] bild, String[] antworten,
			Object[] antwortbilder, int richtigeantwort, String fach, String thema, int Jahr,
			String notiz, int fragenummer, int fragetag)
	{
		_nummer = nummer;
		_fragetext = fragetext;
		_bild = bild;
		_antworten = antworten;
		_antwortbilder = antwortbilder;
		_richtigeantwort = richtigeantwort - 1;
		_fach = fach;
		_thema = thema;
		_jahr = Jahr;
		_notiz = notiz;
		_fragenummer = fragenummer;
		_fragetag = fragetag;

		_selectedAntwort = -1;

	}

	public Frage(boolean random)
	{
		if (random)
		{
			_nummer = 1;
			_fragetext = "fragetext";
			_bild = null;
			String[] s =
			{ "a", "b", "c", "d", "e" };
			_antworten = s;
			_antwortbilder = s;
			_richtigeantwort = 1;
			_fach = "fach";
			_thema = "thema";
			_jahr = 2011;
			_notiz = "notiz";
			_fragenummer = 3;
			_fragetag = 3;
		}

	}

	public int getNummer()
	{
		return _nummer;
	}

	public String getFragetext()
	{
		return _fragetext;
	}

	public byte[] getBild()
	{
		return _bild;
	}

	public String[] getAntworten()
	{
		if (!hatAntwortBilder() && _antworten[0].isEmpty())
		{
			return new String[]
			{ "A", "B", "C", "D", "E" };
		}

		return _antworten;
	}

	/**
	 * Array von ByteArrays
	 * 
	 * @return
	 */
	public Object[] getAntwortbilder()
	{
		return _antwortbilder;
	}

	public byte[] getBildFuerAntwort(int x)
	{
		return (byte[]) _antwortbilder[x];
	}

	/**
	 * Startet bei 0
	 * 
	 * @return
	 */
	public int getRichtigeantwort()
	{
		return _richtigeantwort;
	}

	public String getFach()
	{
		return _fach;
	}

	public String getThema()
	{
		return _thema;
	}

	public int getJahr()
	{
		return _jahr;
	}

	public String getNotiz()
	{
		return _notiz;
	}

	public int getFragenummer()
	{
		return _fragenummer;
	}

	public int getFragetag()
	{
		return _fragetag;
	}

	/**
	 * -1 or 0..5
	 * @param x
	 */
	public void selectAntwort(int x)
	{
		_selectedAntwort = x;
	}

	/**
	 * -1 wenn ncihts angewählt
	 * 
	 * @return
	 */
	public int getSelectedAntwort()
	{
		return _selectedAntwort;
	}

	public boolean hatBild()
	{
		return _bild != null;
	}

	/**
	 * Wenn die Antworten Bilder haben
	 * 
	 * @return
	 */
	public boolean hatAntwortBilder()
	{
		return _antwortbilder[0] != null;
	}
}
